package com.healthy.medical.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.healthy.common.log.annotation.Log;
import com.healthy.common.log.enums.BusinessType;
import com.healthy.common.security.annotation.RequiresPermissions;
import com.healthy.medical.domain.Bookings;
import com.healthy.medical.service.IBookingsService;
import com.healthy.common.core.web.controller.BaseController;
import com.healthy.common.core.web.domain.AjaxResult;
import com.healthy.common.core.utils.poi.ExcelUtil;
import com.healthy.common.core.web.page.TableDataInfo;

/**
 * 医疗机构Controller
 * 
 * @author 束伟
 * @date 2024-03-29
 */
@RestController
@RequestMapping("/Bookings")
public class BookingsController extends BaseController
{
    @Autowired
    private IBookingsService bookingsService;

    /**
     * 查询医疗机构列表
     */
    @RequiresPermissions("medical:Bookings:list")
    @GetMapping("/list")
    public TableDataInfo list(Bookings bookings)
    {
        startPage();
        List<Bookings> list = bookingsService.selectBookingsList(bookings);
        return getDataTable(list);
    }

    /**
     * 导出医疗机构列表
     */
    @RequiresPermissions("medical:Bookings:export")
    @Log(title = "医疗机构", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Bookings bookings)
    {
        List<Bookings> list = bookingsService.selectBookingsList(bookings);
        ExcelUtil<Bookings> util = new ExcelUtil<Bookings>(Bookings.class);
        util.exportExcel(response, list, "医疗机构数据");
    }

    /**
     * 获取医疗机构详细信息
     */
    @RequiresPermissions("medical:Bookings:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bookingsService.selectBookingsById(id));
    }

    /**
     * 新增医疗机构
     */
    @RequiresPermissions("medical:Bookings:add")
    @Log(title = "医疗机构", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Bookings bookings)
    {
        return toAjax(bookingsService.insertBookings(bookings));
    }

    /**
     * 修改医疗机构
     */
    @RequiresPermissions("medical:Bookings:edit")
    @Log(title = "医疗机构", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Bookings bookings)
    {
        return toAjax(bookingsService.updateBookings(bookings));
    }

    /**
     * 删除医疗机构
     */
    @RequiresPermissions("medical:Bookings:remove")
    @Log(title = "医疗机构", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bookingsService.deleteBookingsByIds(ids));
    }
}
